package com.nuoniu.sibanyun.interceptor.handler;

import com.alibaba.fastjson.JSONObject;
import com.nuoniu.sibanyun.common.result.HttpResult;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName MyAuthenticationSuccessHandler
 * @Description 认证成功的处理
 * @Authpr baiqiang
 * @Date 2020/4/29 14:07
 **/
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType("application/json;charset=utf-8");
        HttpResult httpResult = HttpResult.ok("登录成功!");
        System.out.println("MyAuthenticationSuccessHandler->登录成功!");
        response.getWriter().print(JSONObject.toJSONString(httpResult));
    }
}

